package com.wechat.api.util;

import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

/**
 * Created by Liumh on 2018/4/11.
 */
public class TokenUtil {

    @Value("${app_id}")
    private static String APP_ID;
    @Value("${appsecret}")
    private static String APP_SECRET;
    @Value("${wx_get_token_url}")
    private static String accessTokenURL;

    /**
     * 获取全局接口调用唯一凭据
     * @return
     */
    public static String getAccessToken(){
        String doget = HttpClientUtil.doGet(accessTokenURL+"&appid="+APP_ID+"&secret="+APP_SECRET);
        System.out.println(doget);
        Map<String, String> map = JsonUtil.fromJson(doget, Map.class);
        String accessToken = map.get("access_token");   //Token
        //int expiresIn = Integer.parseInt(map.get("expires_in"));   //超时时间
        return accessToken;
    }
}
